package com.yxh.www.author.controller;


import com.yxh.www.author.api.AuthorSmRoleResourceRelationApi;
import com.yxh.www.author.service.SmRoleResourceRelationService;
import com.yxh.www.common.result.Result;
import io.swagger.annotations.Api;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统角色资源关系 前端控制器
 * </p>
 *
 * @author Yangxiaohui
 * @since 2020-05-09
 */
@Api(tags = "系统角色资源关系管理")
@RestController
public class SmRoleResourceRelationController implements AuthorSmRoleResourceRelationApi {

    private final SmRoleResourceRelationService smRoleResourceRelationService;

    public SmRoleResourceRelationController(SmRoleResourceRelationService smRoleResourceRelationService) {
        this.smRoleResourceRelationService = smRoleResourceRelationService;
    }

    /**
     * 新增角色资源关系
     *
     * @param roleId      角色ID
     * @param resourceIds 资源ID集合
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> addSmRoleResourceRelation(String roleId, String[] resourceIds) {
        return smRoleResourceRelationService.addSmRoleResourceRelation(roleId, resourceIds);
    }

    /**
     * 根据角色资源关系ID删除关系
     *
     * @param ids 关系ID集合
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmRoleResourceRelation(String[] ids) {
        return smRoleResourceRelationService.removeSmRoleResourceRelation(ids);
    }

    /**
     * 根据角色ID删除关系
     *
     * @param roleId 角色ID
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmRoleResourceRelationByRoleId(String roleId) {
        return smRoleResourceRelationService.removeSmRoleResourceRelationByRoleId(roleId);
    }

    /**
     * 根据资源ID删除关系
     *
     * @param resourceId 资源ID
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmRoleResourceRelationByResourceId(String resourceId) {
        return smRoleResourceRelationService.removeSmRoleResourceRelationByResourceId(resourceId);
    }

    /**
     * 根据角色ID资源ID删除关系
     *
     * @param roleId     角色ID
     * @param resourceId 资源ID
     * @return 统一响应 {@link Result}
     */
    @Override
    public Result<Object> removeSmRoleResourceRelationByRoleIdAndResourceId(String roleId, String resourceId) {
        return smRoleResourceRelationService.removeSmRoleResourceRelationByRoleIdAndResourceId(roleId, resourceId);
    }
}
